import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ViewController} from 'ionic-angular';
import {HttpProvider} from "@providers/http";
import {DialogProvider} from "@providers/dialog";

/**
 * 师傅列表页面
 */

@IonicPage()
@Component({
  selector: 'page-manager-mworks',
  templateUrl: 'manager-mworks.html',
})
export class ManagerMworksPage {
  param: any = this.navParams.data;
  datas: any[] = [];//人员列表

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private viewCtrl: ViewController,
              private http: HttpProvider,
              private dialog: DialogProvider) {
  }

  ionViewDidLoad() {
    this.getRY();
  }

  dismiss(data?: any) {
    if (data) {
      this.viewCtrl.dismiss(data);
      return;
    }
    this.viewCtrl.dismiss();
  }

  //item点击事件
  dispatch(data: any) {
    if (data.ZCS > 10) {
      this.dialog.showAlert('以超过' + data.ZCS + '单没回执。当日可接单数不足！');
      return;
    }
    this.dialog.showConfirm(() => {
      this.dismiss(data);
    }, '是否确定派工给' + data.VALUE);
  }

  //获取人员
  getRY() {
    this.http.post("/Inbound/invoke.do", {
      interfaceId: "csm.css.jcdy.qcfwquery.fwry",
      data: JSON.stringify(this.param)
    }).subscribe(message => {
      this.datas = message.data;
      // for(let i=0;i<this.datas.length;i++){
      //   console.log("ZCS : " + JSON.stringify(this.datas[i]["ZCS"]));
      //   let v=this.datas[i];
      //   v["Click"]=true;
      //   if(v.ZCS>20){
      //     v["Click"]=false;
      //   }
      // }
      if (this.datas.length == 0) {
        this.dialog.showAlert('该单据所在网点没有合适的师傅！', '', () => {
          this.dismiss();
        });
      }
    }, error => {
      this.dialog.showAlert('请检查网络！' + error);
      this.dialog.hideLoading();
    });
  }
}
